package com.demo.web; /**
 * @author wzm
 * @create 2023-05-05 9:12
 */

import com.demo.pojo.User;
import com.demo.service.UserService;
import com.demo.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/serach")
public class SerachServlet extends HttpServlet {
    private UserService userService = new UserServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");

        String likename = request.getParameter("likename");
        User user = new User();
        user.setUsername("%"+likename+"%");
        //调用service方法
        List<User> list = userService.findByLikeName(user);
        response.getWriter().write(list.toString());
    }
}
